package com.mspbots.rule.queue.timeentry;

import com.mspbots.api.service.TenantService;
import com.mspbots.api.service.TenantUserTimeEntryService;
import com.mspbots.cw.request.TenantTimeLogDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @ClassName com.mspbots.rule.queue.timeentry.NotEnoughTimeQueue
 * @Description TODO
 * @Author Jun
 * @Date 2019/9/2 15:57
 * @Version 1.0
 **/
@Slf4j
@Component
public class NotEnoughTimeLoggedQueue extends TimeEntryBaseQueue {

    private static final String RULE_NAME = "NotEnoughTimeLogged";

    @Autowired
    private TenantService tenantService;
    @Autowired
    private TenantUserTimeEntryService tenantUserTimeEntryService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues = "trigger.NotEnoughTimeLogged")
    public void onQueue(TenantTimeLogDTO tenantTimeLogDTO) {
        log.info("NotEnoughTimeLogged queue: {}", tenantTimeLogDTO.getId());
        try {
           /* if (checkRule(RULE_NAME, tenantTimeLogDTO.getTenantId())) {
                Rules rules = new Rules();
                Class clazz = Class.forName(tenantRuleDTO.getClassName());
                NotEnoughTimeLogged instance = (NotEnoughTimeLogged) clazz.getDeclaredConstructor().newInstance();
                instance.init(tenantRuleDTO, messageProducer, messagesService, tenantUserMappingService, tenantConfigurationService, coreClient);
                instance.setTenantService(tenantService);
                instance.setTenantUserTimeEntryService(tenantUserTimeEntryService);
                instance.setStringRedisTemplate(stringRedisTemplate);
                rules.register(instance);
                Facts facts = new Facts();
                facts.put(BaseRule.FACT, tenantTimeLogDTO);
                rulesEngine.fire(rules, facts);
            }*/
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
